package cn.edu.shou.lab.repository;

import cn.edu.shou.lab.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface StudentRepository extends JpaRepository<Student, String> {
    @Query("select s from Student s where s.student_username=?1 and s.student_password=?2")
    Student getStudentByStudent_usernameAndStudent_password(String student_username, String student_password);

    @Query("select s from Student s where s.student_username=?1")
    Student getStudentByStudent_username(String student_username);

    @Query("select s from Student s where s.student_email=?1")
    Student getStudentByStudent_email(String student_email);

    @Query("select s from Student s where s.student_id=?1")
    Student getStudentByStudent_id(String student_id);

    @Query("update Student s set s.student_password=?1 where s.student_id=?2")
    @Modifying(clearAutomatically = true)
    @Transactional
    void updateStudent_password(String student_password, String student_id);

}
